package bookExercise;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class A14Grouping2 {
    public static void main(String[] args) {
        List<A14Emplyee> list =A14Emplyee.getEmpList();
        Stream<A14Emplyee> stream = list.stream();
        Function<A14Emplyee,String> deptFun =A14Emplyee::getDept;
        Function<A14Emplyee ,String> sexFun =A14Emplyee::getSex;
        Map<String, Map<String, List<A14Emplyee>>> map = stream.
                collect(Collectors.groupingBy(deptFun, Collectors.groupingBy(sexFun)));
        Set<String> set = map.keySet();
        for (String s : set) {
            System.out.println("【"+s+"】部门员工如下：");
            Map<String, List<A14Emplyee>> map2 = map.get(s);
            Set<String> set1 = map2.keySet();
            for (String s1 : set1) {
                System.out.println("["+s1+"] 员工");
                List<A14Emplyee> list2 = map2.get(s1);
                for (A14Emplyee a14Emplyee : list2) {
                    System.out.println(a14Emplyee);
                }
            }
        }
    }
}
